package c.a.a.z.c;

import java.util.ArrayList;
import java.util.List;

/* compiled from: BaseKeyframeAnimation */
public abstract class a<K, A> {
    public final List<b> a = new ArrayList(1);
    public boolean b = false;
    public final d<K> c;
    public float d = 0.0f;
    public c.a.a.f0.c<A> e;
    public A f = null;
    public float g = -1.0f;
    public float h = -1.0f;

    /* compiled from: BaseKeyframeAnimation */
    public interface b {
        void c();
    }

    /* compiled from: BaseKeyframeAnimation */
    public interface d<T> {
        float a();

        boolean b(float f);

        float c();

        c.a.a.f0.a<T> d();

        boolean e(float f);

        boolean isEmpty();
    }

    /* compiled from: BaseKeyframeAnimation */
    public static final class c<T> implements d<T> {
        public c(a aVar) {
        }

        public float a() {
            return 1.0f;
        }

        public boolean b(float f) {
            throw new IllegalStateException("not implemented");
        }

        public float c() {
            return 0.0f;
        }

        public c.a.a.f0.a<T> d() {
            throw new IllegalStateException("not implemented");
        }

        public boolean e(float f) {
            return false;
        }

        public boolean isEmpty() {
            return true;
        }
    }

    /* compiled from: BaseKeyframeAnimation */
    public static final class e<T> implements d<T> {
        public final List<? extends c.a.a.f0.a<T>> a;
        public c.a.a.f0.a<T> b;
        public c.a.a.f0.a<T> c = null;
        public float d = -1.0f;

        public e(List<? extends c.a.a.f0.a<T>> list) {
            this.a = list;
            this.b = f(0.0f);
        }

        public float a() {
            List list = this.a;
            return ((c.a.a.f0.a) list.get(list.size() - 1)).b();
        }

        public boolean b(float f) {
            c.a.a.f0.a aVar = this.c;
            c.a.a.f0.a aVar2 = this.b;
            if (aVar == aVar2 && this.d == f) {
                return true;
            }
            this.c = aVar2;
            this.d = f;
            return false;
        }

        public float c() {
            return ((c.a.a.f0.a) this.a.get(0)).c();
        }

        public c.a.a.f0.a<T> d() {
            return this.b;
        }

        public boolean e(float f) {
            if (this.b.a(f)) {
                return this.b.d() ^ 1;
            }
            this.b = f(f);
            return true;
        }

        public final c.a.a.f0.a<T> f(float f) {
            List list = this.a;
            c.a.a.f0.a aVar = (c.a.a.f0.a) list.get(list.size() - 1);
            if (f >= aVar.c()) {
                return aVar;
            }
            for (int size = this.a.size() - 2; size >= 1; size--) {
                c.a.a.f0.a aVar2 = (c.a.a.f0.a) this.a.get(size);
                if (this.b != aVar2 && aVar2.a(f)) {
                    return aVar2;
                }
            }
            return (c.a.a.f0.a) this.a.get(0);
        }

        public boolean isEmpty() {
            return false;
        }
    }

    /* compiled from: BaseKeyframeAnimation */
    public static final class f<T> implements d<T> {
        public final c.a.a.f0.a<T> a;
        public float b = -1.0f;

        public f(List<? extends c.a.a.f0.a<T>> list) {
            this.a = (c.a.a.f0.a) list.get(0);
        }

        public float a() {
            return this.a.b();
        }

        public boolean b(float f) {
            if (this.b == f) {
                return true;
            }
            this.b = f;
            return false;
        }

        public float c() {
            return this.a.c();
        }

        public c.a.a.f0.a<T> d() {
            return this.a;
        }

        public boolean e(float f) {
            return this.a.d() ^ 1;
        }

        public boolean isEmpty() {
            return false;
        }
    }

    public a(List<? extends c.a.a.f0.a<K>> list) {
        d cVar;
        if (list.isEmpty()) {
            cVar = new c(null);
        } else {
            e fVar;
            if (list.size() == 1) {
                fVar = new f(list);
            } else {
                fVar = new e(list);
            }
            cVar = fVar;
        }
        this.c = cVar;
    }

    public c.a.a.f0.a<K> a() {
        c.a.a.f0.a d = this.c.d();
        c.a.a.c.a("BaseKeyframeAnimation#getCurrentKeyframe");
        return d;
    }

    public float b() {
        if (this.h == -1.0f) {
            this.h = this.c.a();
        }
        return this.h;
    }

    public float c() {
        c.a.a.f0.a a = a();
        if (a.d()) {
            return 0.0f;
        }
        return a.d.getInterpolation(d());
    }

    public float d() {
        if (this.b) {
            return 0.0f;
        }
        c.a.a.f0.a a = a();
        if (a.d()) {
            return 0.0f;
        }
        return (this.d - a.c()) / (a.b() - a.c());
    }

    public A e() {
        float c = c();
        if (this.e == null && this.c.b(c)) {
            return this.f;
        }
        Object f = f(a(), c);
        this.f = f;
        return f;
    }

    public abstract A f(c.a.a.f0.a<K> aVar, float f);

    public void g() {
        for (int i = 0; i < this.a.size(); i++) {
            ((b) this.a.get(i)).c();
        }
    }

    public void h(float f) {
        if (!this.c.isEmpty()) {
            if (this.g == -1.0f) {
                this.g = this.c.c();
            }
            float f2 = this.g;
            if (f < f2) {
                if (f2 == -1.0f) {
                    this.g = this.c.c();
                }
                f = this.g;
            } else if (f > b()) {
                f = b();
            }
            if (f != this.d) {
                this.d = f;
                if (this.c.e(f)) {
                    g();
                }
            }
        }
    }

    public void i(c.a.a.f0.c<A> cVar) {
        c.a.a.f0.c cVar2 = this.e;
        this.e = null;
    }
}
